package com.party.controller.sys.user;
import com.party.model.Lodge;
import com.party.model.SysUser;
import com.party.service.lodge.LodgeService;
import com.party.service.sys.SysUserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 系统用户
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 13-3-31
 * Time: 下午3:18
 * To change this template use File | Settings | File Templates.
 */
@Controller
@RequestMapping(value = "/sys/lodgeinfo")
public class SysLodgeInfoController {

    @Resource
    SysUserService sysUserServiceService;

    @Resource
    LodgeService lodgeService;

    private int pageSize = 9;

    /**
     * 用户列表
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/show")
    public ModelAndView index(
            @RequestParam(value = "id")Integer id,
            HttpServletRequest request,
            HttpServletResponse response
    ) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("uid",id);
        SysUser sysUser=sysUserServiceService.getUser(id);
        modelAndView.addObject("lodgeid",sysUser.getLodgeid());

        List<Lodge> listLodge=lodgeService.getAllLodge();
        modelAndView.addObject("listLodge",listLodge);
        modelAndView.setViewName("/sys/sysmange/sys_user_lodge");
        return modelAndView;
    }

    /**
     * 更新
     * @return
     */
    @RequestMapping(value = "/editData")
    public ModelAndView editData(
            @RequestParam(value = "uid")Integer uid,
            @RequestParam(value = "lodgeid")Integer lodgeid,
            HttpSession session,
            HttpServletRequest request,
            HttpServletResponse response) {
        SysUser sysUser=new SysUser();
        sysUser.setUid(uid);
        sysUser.setLodgeid(lodgeid);
        String msg="";
        int num=sysUserServiceService.update(sysUser);
        if(num>0){
            msg="编辑成功";
        }else{
            msg="编辑失败";
        }

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("msg",msg);
        modelAndView.setViewName("/sys/sysmange/sys_user_lodge");
        return modelAndView;
    }

}

